#define FSFACESDK_EXPORTS
#ifdef FSFACESDK_EXPORTS
#define FSFACESDK_API __declspec(dllexport)
#else
#define FSFACESDK_API __declspec(dllimport)
#endif

#include "FiStdDefEx.h"

struct FaceAngle
{
	int   yaw;//angle of yaw,from -90 to +90,left is negative,right is postive
	int   pitch;//angle of pitch,from -90 to +90,up is negative,down is postive
	int   roll;//angle of roll,from -90 to +90,left is negative,right is postive
	float confidence;//confidence of face pose(from 0 to 1,0.6 is suggested threshold)
};

struct THFI_FacePos
{
	RECT		rcFace;//coordinate of face
	POINT		ptLeftEye;//coordinate of left eye
	POINT		ptRightEye;//coordinate of right eye
	POINT		ptMouth;//coordinate of mouth
	POINT		ptNose;//coordinate of nose								
	FaceAngle	fAngle;//value of face angle
	int			nQuality;//quality of face(from 0 to 100)
	BYTE   		pFacialData[512];//facial data
	THFI_FacePos()
	{
		memset(&rcFace,0,sizeof(RECT));
		memset(&ptLeftEye,0,sizeof(POINT));
		memset(&ptRightEye,0,sizeof(POINT));
		memset(&ptMouth,0,sizeof(POINT));
		memset(&ptNose,0,sizeof(POINT));
		memset(&fAngle,0,sizeof(FaceAngle));
		nQuality=0;
		memset(pFacialData, 0, 512);
	}
};

/*
 The FSRegist function.

 Parameters:
	pollCode[output],pollCode for register.
 Return Values:
	If the function succeeds, the return value is pollCode length.
	If the function fails, the return value is negative.
	error code:
		<0,get register error.
 Remarks:
	No remark.
*/
extern "C" FSFACESDK_API int FSRegist(BYTE* pollCode);

/*
 The FSInit function.

 Parameters:
	nChannelNum[intput],algorithm channel num,for multi-thread mode,one thread uses one channel.
	licenseCode[input],licenseCode for run.
 Return Values:
	If the function succeeds, the return value is Channel Num.
	If the function fails, the return value is negative.
	error code:
		<=-90,invalid license.
		-1,open file "feadb.db*" error
		-2,check  file "feadb.db*" error
		-3,read  file "feadb.db*" error
 Remarks:
	No remark.
*/
extern "C" FSFACESDK_API int FSInit(int nChannelNum, BYTE* licenseCode);

/*
 The FSSize function will return face feature size.

 Parameters:
	No parameter.
 Return Values:
	If the function succeeds, the return value is face feature size.
	If the function fails, the return value is 0 or nagative;
	error code:
		<=-90,invalid license.
 Remarks:
	No remark.
*/
extern "C" FSFACESDK_API int FSSize();

/*
 The FSDetectFace function execute face detection only.

 Parameters:
	nChannelID[input],channel ID(from 0 to nChannelNum-1)
	pImage[input],image data buffer,RGB24 format.
	bpp[input],bits per pixel(24-RGB24 image),must be 24
	nWidth[input],image width.
	nHeight[input],image height.
	pfps[output],the facial position information.
	nMaxFaceNums[input],max face nums that you want
	nSampleSize[input],down sample size(image down sample) for detect image,if it is 0,will detect by original image.
 Return Values:
	If the function succeeds, the return value is face number.
	If the function fails, the return value is negative.
	error code:
		<=-90,invalid license.
		-1,nChannelID is invalid or SDK is not initialized
		-2,image data is invalid,please check function parameter:pImage,bpp,nWidth,nHeight
		-3,pfps or nMaxFaceNums is invalid.
 Remarks:
	1.image data buffer(pImage)	size must be nWidth*(bpp/8)*nHeight.
	2.pfps must be allocated by caller,the memory size is nMaxFaceNums*sizeof(THFI_FacePos).
	3.if image has face(s),face number less than or equal to nMaxFaceNums
*/
extern "C" FSFACESDK_API int FSDetectFace(short nChannelID, BYTE* pImage, int bpp, int nWidth, int nHeight, THFI_FacePos pfps[], int nMaxFaceNums, int nSampleSize=640);

/*
 The EF_Extract function execute face feature extraction from one photo

 Parameters:
	nChannelID[input],channel ID(from 0 to nChannelNum-1)
	pBuf[input],point to an image buffer,BGR format.
	nWidth[input],the image width.
	nHeight[input],the image height.
	nChannel[input],image buffer channel,must be 3
	ptfp[input],the facial data of a face.
	pFeature[output],the face feature buffer
 Return Values:
	If the function succeeds, the return value is 1.
	If the function fails, the return value is nagative.
	error code:
		<=-90,invalid license.
		-1,pBuf,ptfp,pFeature is NULL
		-2,nChannelID is invalid or SDK is not initialized
 Remarks:
	No remark.
*/
extern "C" FSFACESDK_API int FSExtract(short nChannelID, BYTE* pBuf, int nWidth, int nHeight, int nChannel, THFI_FacePos *ptfp, BYTE* pFeature);

/*
 The EF_Extract_M function execute face feature extraction for muti-faces from one photo

 Parameters:
	nChannelID[input],channel ID(from 0 to nChannelNum-1)
	pBuf[input],point to an image buffer,BGR format.
	nWidth[input],the image width.
	nHeight[input],the image height.
	nChannel[input],image buffer channel,must be 3
	ptfps[input],the facial data of muti-faces
	pFeatures[output],the face feature buffer for muti-faces
	nFaceNum[input],the face number
 Return Values:
	If the function succeeds, the return value is 1.
	If the function fails, the return value is 0 or nagative.
	error code:
		<=-90,invalid license.
		-1,pBuf,ptfps,pFeatures is NULL
		-2,nChannelID is invalid or SDK is not initialized
 Remarks:
	No remark.
*/
extern "C" FSFACESDK_API int FSExtract_M(short nChannelID, BYTE* pBuf, int nWidth, int nHeight, int nChannel, THFI_FacePos ptfps[], BYTE* pFeatures, int nFaceNum);


/*
 The EF_Compare function execute two face features compare.

 Parameters:
	pFeature1[input],point to one face feature buffer.
	pFeature2[input],point to another face feature buffer.
 Return Values:
	If the function succeeds, the return value is the two face features's similarity.
	If the function fails, the return value is nagative.
	error code:
		<=-90,invalid license.
 Remarks:
	No remark.
*/
extern "C" FSFACESDK_API float FSCompare(BYTE* pFeature1, BYTE* pFeature2);

/*
 The EF_Release function will release the Face Feature (THFeature) algorithm module

 Parameters:
	No parameter.
 Return Values:
	No return value.
 Remarks:
	This function can be called one time at program Un-Initialization.
*/
extern "C" FSFACESDK_API void FSRelease();